import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;

/**
 * 合并表记录
 * Created by JiaJia on 2019/6/19 0019.
 */
public class HuaWei008 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            int n=Integer.parseInt(scanner.nextLine());
            SortedMap<Integer,Integer> map=new TreeMap<>();
            for (int i = 0; i <n ; i++) {
                String[] nums=scanner.nextLine().split("\\s+");
                addPare(nums,map);
            }
            System.out.println(mapToString(map));
        }
        scanner.close();
    }
    private static void addPare(String[] nums,SortedMap<Integer,Integer> map){
        int k=Integer.parseInt(nums[0]);
        int v=Integer.parseInt(nums[1]);
        if (map.containsKey(k)){
            map.put(k,map.get(k)+v);
        }else {
            map.put(k,v);
        }
    }
    private static String mapToString(SortedMap<Integer,Integer> map){
        StringBuilder sb=new StringBuilder();
        for (SortedMap.Entry<Integer,Integer> e:map.entrySet()) {
            sb.append(e.getKey()).append(" ").append(e.getValue()).append("\n");
        }
        return sb.toString();
    }
}